package b1.conifg
{
	import b1.players.PlayerInfoHelper;
	
	public class Config
	{
		public static var levelConfigs:Array;
		public static var animalConfigs:Array;
		public static var magicConfigs:Array;
		public static var objectConfigs:Array;
		public static var clueConfigs:Array;
		public static var obstacleConfigs:Array;
		public static var virtualPlayerConfigs:Array;
		public static var languageConfig:LanguageConfig;
		//特殊案件
		public static var specialCaseConfigs:Array;
		//节日案件
		public static var festivalSpecialCaseConfigs:Array;
		//主线任务
		public static var taskConfigs:Array;
		//节日任务
		public static var festivalTaskConfigs:Array;
		//排名信息
		public static var rankConfigs:Array;
		//每一个等级对应的增加技能点
		public static var skillPointsPerLevel:int;
		//游戏中的一天对应现实时间中的秒数
		public static var secondsPerDay:int;
		//白天和黑夜的经验加成
		public static var expBonusForDayNight:Number; 
		//每一个涉案骨头需要罪犯坐牢的时间（秒）
		public static var secondsInPrisonPerBone:int;
		//坐牢的最短时间
		public static var baseSecondsInPrison:int;
		//每一秒需要缴纳的保释骨头
		public static var bonePerSecondsInPrison:Number;
		//当错误判断罪犯时索赔比（有案件，相对涉案骨头的百分比）
		public static var claimRatioForWrongIdentification:int;
		//当错误抓捕罪犯时索赔的骨头（没有案件，并且对象没有被通缉）
		public static var claimBonesForWrongIdentification:int;
		//跑路后的骨头的加成
		public static var compensationRaioForRunAway:Number;
		//跑路时的代价，骨头数和智力差相关
		public static var bonePerIntelligenceForRunAway:int;
		//跑路时的代价，基础骨头数
		public static var baseBoneForRunAway:int;
		//传家宝箱满的时间间隔（秒）
		public static var heirloomBoxFullTime:int;
		//邻居数
		public static var neighborNum:int;
		//动物的初始名字
		public static var animalNames:Array;
		//骨头的种类
		public static var boneTypeNum:int;
		
		//战斗持续时间
		public static var duration:int;
		//每场战斗胜利后的基础经验
		public static var baseExp:int;
		//根据对手等级的经验加成
		public static var addExpPerLevel:int;
		//失败后的经验比例
		public static var expRatioForLose:Number;
		//完美胜利的经验比例
		public static var expRatioForPerfectWin:Number;
		//优秀胜利的经验比例
		public static var expRatioForGoodWin:Number;
		//险胜胜利的经验比例 （险胜）
		public static var expRatioForLittleWin:Number;
		//秒杀掉落传家宝的概率
		public static var heirloomRatioForPerfectWin:Number;
		//完胜掉落传家宝的概率
		public static var heirloomRatioForGoodWin:Number;
		//险胜掉落传家宝的概率
		public static var heirloomRatioForLittleWin:Number;
		//胜利掉落传家宝的概率
		public static var heirloomRatioForWin:Number;
		//奖励骨头
		//在这个等级差距之外抢不到骨头
		public static var levelBalance:int;
		//每个等级差对应的骨头数
		public static var timesBalance:int;
		//侦探案件获得的经验（每个案件骨头对应的经验）
		public static var expPerCaseBone:int;
		
		//乌鸦飞行的最晚事件
		public static var crowFlyTime:int;
		//被击中说话概率
		public static var speakProbability:int;
		//传家骨回复发生概率
		public static var HeirloomPro:int;
		
		public static var HeirloomHp:int;
		//助手的名字
		public static var assistantName:String;
		//助手的图片
		public static var assistantImg:String;
		
		public static var moveAfterHitPro:Number;
		//卖出打折 0.9表示9折
		public static var disCount:Number;
		//装备名字
		public static var equipName:Array;
		//装备字体颜色
		public static var equipColor1:Array;
		//装备发光颜色
		public static var equipColor2:Array;
		//装备名称
		public static var equipColorName:Array;
		//装备颜色->评分
		public static var equipColorScore:Array;
		//装备评分->颜色
		public static var equipScoreColor:Object;
		
		public function Config()
		{
			
		}
		
		public static function parseXML(dataXML:XML):void
		{
			//解析助手的信息
			assistantImg = dataXML.basic.assistantImg;
			assistantName = dataXML.basic.assistantName;
			//解析时间信息
			secondsPerDay = parseInt(dataXML.basic.secondsPerDay);
			expBonusForDayNight = parseFloat(dataXML.basic.expBonusForDayNight);
			secondsInPrisonPerBone = parseInt(dataXML.basic.secondsInPrisonPerBone);
			baseSecondsInPrison = parseInt(dataXML.basic.baseSecondsInPrison);
			bonePerSecondsInPrison = parseFloat(dataXML.basic.bonePerSecondsInPrison);
			skillPointsPerLevel = parseInt(dataXML.basic.skillPointsPerLevel);
			claimRatioForWrongIdentification = parseInt(dataXML.basic.claimRatioForWrongIdentification);
			claimBonesForWrongIdentification = parseInt(dataXML.basic.claimBonesForWrongIdentification);
			compensationRaioForRunAway = parseFloat(dataXML.basic.compensationRaioForRunAway);
			heirloomBoxFullTime = parseInt(dataXML.basic.heirloomBoxFullTime);
			neighborNum = parseInt(dataXML.basic.neighborNum);
			crowFlyTime = parseInt(dataXML.basic.crowFlyTime);
			speakProbability = parseInt(dataXML.basic.speakProbability);
			compensationRaioForRunAway = parseInt(dataXML.basic.compensationRaioForRunAway);
			bonePerIntelligenceForRunAway = parseInt(dataXML.basic.bonePerIntelligenceForRunAway);
			baseBoneForRunAway = parseInt(dataXML.basic.baseBoneForRunAway);
			disCount = parseFloat(dataXML.basic.disCount);
			//装备名字
			equipName = dataXML.basic.equipName.split(",");
			//解读颜色信息
			equipColor1 = new Array();
			var equipColor1s:Array = dataXML.basic.equipColor1.split(",");
			for (var i:int = 0; i < equipColor1s.length; i++)
				equipColor1.push(parseInt(equipColor1s[i]));
			equipColor2 = new Array();
			var equipColor2s:Array = dataXML.basic.equipColor2.split(",");
			for (i = 0; i < equipColor2s.length; i++)
				equipColor2.push(parseInt(equipColor2s[i]));
			equipColorName = dataXML.basic.equipColorName.split(",");
			//解析装备评分
			equipColorScore = new Array();
			equipScoreColor = new Object();
			var equipScoreStrs:Array = dataXML.basic.equipScore.split(",");
			for (i = 0; i < equipScoreStrs.length; i++)
			{
				equipColorScore.push(parseInt(equipScoreStrs[i]));
				equipScoreColor[parseInt(equipScoreStrs[i])] = i;
			}
			//解析动物初始名字
			animalNames = new Array();
			animalNames = dataXML.basic.animalNames.split(",");
			//解析等级信息
			levelConfigs = new Array();
			for (i = 0; i < dataXML.levelInfo.level.length(); i++)
			{
				levelConfigs.push(new LevelConfig(dataXML.levelInfo.level[i]));
			}
			//魔法信息
			magicConfigs = new Array();
			for (i = 0; i < dataXML.magicInfo.magic.length(); i++)
			{
				magicConfigs.push(new MagicConfig(dataXML.magicInfo.magic[i]));
			}
			//解析动物信息
			animalConfigs = new Array();
			for (i = 0; i < dataXML.animalInfo.animal.length(); i++)
			{
				animalConfigs.push(new AnimalConfig(dataXML.animalInfo.animal[i]));
			}
			//解析物品信息
			objectConfigs = new Array();
			boneTypeNum = 0;
			for (i = 0; i < dataXML.objectInfo.object.length(); i++)
			{
				var objectType:int = parseInt(dataXML.objectInfo.object[i].type);
				var objectConfig:ObjectConfig;
				//装备
				if (objectType == 2)
				{
					var objectColor:int = parseInt(dataXML.objectInfo.object[i].color);
					var equipConfig:EquipConfig;
					if (objectColor == 0)
					{
						equipConfig = new EquipConfig(dataXML.objectInfo.object[i]);
						objectConfig = equipConfig;
					}
					else 
					{
						var extend:int = parseInt(dataXML.objectInfo.object[i].extend);
						equipConfig = new EquipConfig(dataXML.objectInfo.object[extend]);
						equipConfig.baseIndex = extend;
						equipConfig.index = parseInt(dataXML.objectInfo.object[i].index);
						equipConfig.color = parseInt(dataXML.objectInfo.object[i].color);
						equipConfig.colorAddHealthPoint = parseInt(dataXML.objectInfo.object[i].extraAddHealthPoint);
						equipConfig.colorAddIntelligence = parseInt(dataXML.objectInfo.object[i].extraAddIntelligence);
						equipConfig.colorAddSpeed = parseInt(dataXML.objectInfo.object[i].extraAddSpeed);
						equipConfig.colorAddVitalityPoint = parseInt(dataXML.objectInfo.object[i].extraAddVitalityPoint);
						equipConfig.colorDescribe = dataXML.objectInfo.object[i].extraDescription;
						equipConfig.durability = parseInt(dataXML.objectInfo.object[i].durability);
						equipConfig.onSaleFlag = Boolean(parseInt(dataXML.objectInfo.object[i].onSaleFlag));
						equipConfig.priceBones = parseInt(dataXML.objectInfo.object[i].priceBones);
						objectConfig = equipConfig;
						//更新基础装备的颜色信息
						var baseEquipConfig:EquipConfig = objectConfigs[extend];
						baseEquipConfig.colorIndexes[equipConfig.color] = equipConfig.index;
					}
				}
				//弓（发射器）
				else if (objectType == 3)
				{
					var launcherConfig:LauncherConfig = new LauncherConfig(dataXML.objectInfo.object[i]);
					objectConfig = launcherConfig;
				}
				//其他物品
				else
				{
					objectConfig = new ObjectConfig(dataXML.objectInfo.object[i]);
					if (objectType == 0)
					{
						boneTypeNum++;
					}
				}
				objectConfigs.push(objectConfig);
			}
			//解析线索信息
			clueConfigs = new Array();
			for (i = 0; i < dataXML.clueInfo.clue.length(); i++)
			{
				clueConfigs.push(new ClueConfig(dataXML.clueInfo.clue[i]));
			}
			//解析障碍物信息
			obstacleConfigs = new Array();
			for (i = 0; i < dataXML.obstacleInfo.obstacle.length(); i++)
			{
				obstacleConfigs.push(new ObstacleConfig(dataXML.obstacleInfo.obstacle[i]));
			}		
			//解析任务信息
			taskConfigs = new Array();
			for (i = 0; i < dataXML.taskInfo.task.length(); i++)
			{
				taskConfigs.push(new TaskConfig(dataXML.taskInfo.task[i]));
			}
			//解析节日任务信息
			festivalTaskConfigs = new Array();
			for (i = 0; i < dataXML.taskInfo.festivalTask.length(); i++)
			{
				festivalTaskConfigs.push(new TaskConfig(dataXML.taskInfo.festivalTask[i]));
			}
			//解析语言
			languageConfig = new LanguageConfig(dataXML.languageInfo[0]);
			//解析战斗信息
			duration = parseInt(dataXML.fightInfo.duration);
			baseExp = parseInt(dataXML.fightInfo.baseExp);
			addExpPerLevel = parseInt(dataXML.fightInfo.addExpPerLevel);
			expRatioForLose = parseFloat(dataXML.fightInfo.expRatioForLose);
			expRatioForPerfectWin = parseFloat(dataXML.fightInfo.expRatioForPerfectWin);
			expRatioForGoodWin = parseFloat(dataXML.fightInfo.expRatioForGoodWin);
			expRatioForLittleWin = parseFloat(dataXML.fightInfo.expRatioForLittleWin);
			heirloomRatioForPerfectWin = parseFloat(dataXML.fightInfo.heirloomRatioForPerfectWin);
			heirloomRatioForGoodWin = parseFloat(dataXML.fightInfo.heirloomRatioForGoodWin);
			heirloomRatioForLittleWin = parseFloat(dataXML.fightInfo.heirloomRatioForLittleWin);
			heirloomRatioForWin = parseFloat(dataXML.fightInfo.heirloomRatioForWin);
			levelBalance = parseInt(dataXML.fightInfo.levelBalance);
			timesBalance = parseInt(dataXML.fightInfo.timesBalance);
			expPerCaseBone = parseInt(dataXML.fightInfo.expPerCaseBone);
			HeirloomPro = parseInt(dataXML.fightInfo.HeirloomPro);
			HeirloomHp = parseInt(dataXML.fightInfo.HeirloomHp);
			moveAfterHitPro = parseFloat(dataXML.fightInfo.moveAfterHitPro);
			//解析排名信息
			rankConfigs = new Array();
			for (i = 0; i < dataXML.rankInfo.rank.length(); i++)
			{
				rankConfigs.push(new RankConfig(dataXML.rankInfo.rank[i]));
			}
			//解析节日特殊事件的信息
			festivalSpecialCaseConfigs = new Array();
			for (i = 0; i < dataXML.specialCaseInfo.festivalSpecialCase.length(); i++)
			{
				festivalSpecialCaseConfigs.push(new SpecialCaseConfig(dataXML.specialCaseInfo.festivalSpecialCase[i]));
			}
			//解析特殊事件的信息
			specialCaseConfigs = new Array();
			for (i = 0; i < dataXML.specialCaseInfo.specialCase.length(); i++)
			{
				specialCaseConfigs.push(new SpecialCaseConfig(dataXML.specialCaseInfo.specialCase[i]));
			}
			//解析虚拟玩家的信息
			virtualPlayerConfigs = new Array();
			for (i = 0; i < dataXML.virtualPlayerInfo.virtualPlayer.length(); i++)
			{
				var virtualPlayer:VirtualPlayerConfig = new VirtualPlayerConfig(dataXML.virtualPlayerInfo.virtualPlayer[i]);
				virtualPlayerConfigs.push(virtualPlayer);
				PlayerInfoHelper.getInstance().players[virtualPlayer.id] = virtualPlayer;
			}
		}
	}
}